const getRawBody = require('raw-body')

module.exports.initializer = function (context, callback) {
    console.log("initializer invoked");
    callback(null, '');
}

module.exports.helloWorld = function (request, response, context) {
    // get request body
    getRawBody(request, function (err, body) {
        // var respBody = {
        //     headers: request.headers,
        //     url: request.url,
        //     path: request.path,
        //     queries: request.queries,
        //     method: request.method,
        //     clientIP: request.clientIP,
        //     body: body.toString()
        // };
        const queries = request.queries;
        console.log('===queries===', queries);
        console.log('===headers===', request.headers);
        console.log('===body===', body.toString());
        console.log('===path===', request.path);
        var message = "hello world";
        if (queries.hasOwnProperty('name')) {
            message = `${message}, hello ${queries.name}`
        }
        const respBody = {
            code: "100",
            message: message
        }
        response.setStatusCode(200);
        response.setHeader('content-type', 'application/json;charset=UTF-8');
        response.send(JSON.stringify(respBody, null, 4));
    });
};